#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>

/*
Header header
  uint32 seq
  time stamp
  string frame_id
uint32 height                  # 指定点云数据的高度，一般为1
uint32 width                   # 指定点云数据的宽度，即点云中点的数量
sensor_msgs/PointField[] fields # 描述每个点的属性，如坐标、颜色、法向量等
bool is_bigendian              # 是否为大端字节序
uint32 point_step              # 每个点的字节数
uint32 row_step                # 每行数据的字节数，即width*point_step
uint8[] data                   # 所有点的数据，每个点的数据根据fields中描述的属性
 */
void pointCloudCallback(const sensor_msgs::PointCloud2ConstPtr &msg) {
    // 获取点云中点的数量
    int num_points = msg->width * msg->height;
    ROS_INFO("Received point cloud with %d points", num_points);
}

int main(int argc, char **argv) {
    ros::init(argc, argv, "cre_point_cloud_subscriber");
    ros::NodeHandle nh;
    ros::Subscriber sub = nh.subscribe<sensor_msgs::PointCloud2>("/point_cloud_topic", 1, pointCloudCallback);
    ros::spin();
    return 0;
}